var express = require("express")
const cors = require('cors');
var app = express();
app.use(cors())
var server = require("http").Server(app);
server.listen(1122)
var socket = require("socket.io")(server)

// 添加一个连接监听器
socket.on('connection', function(client){
    console.log('connected');
    // 成功！现在开始监听接收到的消息
    client.on('message',function(event){
        console.log('Received message from client!',event);
    });
    client.on('disconnect',function(){
        // clearInterval(interval);
        console.log('Server has disconnected');
    });
    client.on("open", function(data){
        console.log("------------open---------------")
    })
    // var interval= setInterval(function() {
    //     client.send('This is a message from the server! ' + new Date().getTime());
    //     console.log('This is a message from the server! ' + new Date().getTime());
    // },5000);
});